package adapter.codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

public class ByteArrayEncoder extends ProtocolEncoderAdapter {

	public void encode(IoSession ioSession, Object object, ProtocolEncoderOutput protocolEncoderOutput) throws Exception {
		byte[] bytes = (byte[]) object;
		int totalLength = bytes.length;
		IoBuffer buf = IoBuffer.allocate(totalLength);
		buf.put(bytes);
		buf.flip();
		ioSession.write(buf);
	}

}
